package com.neu.servlet.wty;

import com.neu.service.wty.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "forgetServlet", urlPatterns = {"/forgetServlet.get"})
public class forgetServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String u_mail=request.getParameter("u_mail");
        String newPwd=request.getParameter("newPwd");
        System.out.println(u_mail);
        u_mail=u_mail.substring(8);

        System.out.println(u_mail);
        System.out.println(newPwd);
        UserService userService=new UserService();
        boolean flag=userService.alterPwdByEmail(newPwd,u_mail);
        if (flag){
            System.out.println("成功");
                request.setAttribute("flag",flag);
                request.getRequestDispatcher("newPwd.jsp").forward(request,response);
        }else {
            System.out.println("失败");
            request.setAttribute("flag",flag);
            request.getRequestDispatcher("newPwd.jsp").forward(request,response);
        }

    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}